package com.atguigu.servlet;

import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/view1Servlet")
public class View1Servlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("View1Servlet service");
        // 相对路径 与资源相对路径类似,替换掉自己这层
        RequestDispatcher rd = req.getRequestDispatcher("WEB-INF/view/view1.html");
        // 绝对路径 重定向时/出发点是http://localhost:8080/ ; 请求转发时 / 出发点是http://localhost:8080/项目上下文/
        rd.forward(req, resp);
    }
}
